package Command;

import java.io.RandomAccessFile;
import java.util.ArrayList;

import Server.Command;

public class HomerDecoration extends CommandDecorator {
	private ArrayList<String> quotes = new ArrayList<String>();

	public HomerDecoration(Command cmd) {
		super(cmd);
	}

	public String execute() {


		return super.execute() + this.getQuote();
	}

	public String undo() {
		return super.undo();
	}
	
	private String getQuote() {
		fillQuotes();
		Integer randomNum = 0 + (int)(Math.random()*quotes.size()); 
		String quote;
		if (quotes.isEmpty()) {
			quote = "No quotes to use as decoration.";
		} else {
			quote = quotes.get(randomNum);
		}
		return quote;
	}

	private void fillQuotes() {
		if (quotes.isEmpty()) {
			quotes = new ArrayList<String>();
			RandomAccessFile raf;

			try {
				raf = new RandomAccessFile("homer.txt", "r");
				String line;
				while ((line = raf.readLine()) != null) {
					if (line.trim().length() < 66) {
						quotes.add("\n" + line);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}


	}
}
